package leetcode.剑指offer.剑指II;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/8/18 20:52
 * @description：https://leetcode-cn.com/problems/XltzEq/
 */
public class 有效的回文 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.isPalindrome("0P"));
    }

    class Solution {
        public boolean isPalindrome(String s) {
            int l = 0;
            int r = s.length() - 1;
            s = s.toLowerCase();
            while (l < r) {
                while (l < r && (s.charAt(l) < 'a' || s.charAt(l) > 'z')) {
                    l++;
                }
                while (l < r && (s.charAt(r) < 'a' || s.charAt(r) > 'z')) {
                    r--;
                }
                if (l == r || s.charAt(l) != s.charAt(r)) return false;
                l++;
                r--;
            }
            return true;
        }
    }
}
